package pl.edu.agh.iosr.gamblingzone.action;

import java.util.ArrayList;
import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;

import pl.edu.agh.iosr.gamblingzone.model.Group;
import pl.edu.agh.iosr.gamblingzone.model.Participant;
import pl.edu.agh.iosr.gamblingzone.model.User;
import pl.edu.agh.iosr.gamblingzone.dao.GroupDAO;
import pl.edu.agh.iosr.gamblingzone.dao.ParticipantDAO;
import pl.edu.agh.iosr.gamblingzone.dao.ejb.GroupDAOBean;
import pl.edu.agh.iosr.gamblingzone.dao.ejb.ParticipantDAOBean;
import pl.edu.agh.iosr.gamblingzone.dao.ejb.UserDAOBean;

@Stateless
@Name("groupsManage")
public class GroupManageAction implements GroupManage {

	@PersistenceContext
	EntityManager entityManager;

	private List<Group> allGroups;

	private GroupDAO groupDAO;

	private void setupDAO() {
		if (groupDAO == null) {
			groupDAO = new GroupDAOBean();
			((GroupDAOBean) groupDAO).setEntityManager(entityManager);
		}
	}

	@Out
	public List<Group> getAllGroups() {
		setupDAO();
		allGroups = groupDAO.findAll();

		return allGroups;
	}

	public void removeGroup(Group g) {
		groupDAO.makeTransient(g);
	}

	public void addGroup() {
		setupDAO();
		// TODO

	}

}
